package com.ruoyi.web.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.web.domain.vo.GuTagVo;
import com.ruoyi.web.domain.vo.GuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.web.domain.GuGupiao;
import com.ruoyi.web.service.IGuGupiaoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 股票库Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/gupiao")
public class GuGupiaoController extends BaseController
{
    @Autowired
    private IGuGupiaoService guGupiaoService;

    /**
     * 查询股票库列表
     */
    @RequiresPermissions("web:gupiao:list")
    @GetMapping("/list")
    public TableDataInfo list(GuGupiao guGupiao)
    {
        startPage();
        List<GuGupiao> list = guGupiaoService.selectGuGupiaoList(guGupiao);
        return getDataTable(list);
    }
    /**
     * 查询股票库列表
     */
    @GetMapping("/listAll")
    public TableDataInfo listAll(GuGupiao guGupiao)
    {

        List<GuGupiao> list = guGupiaoService.selectGuGupiaoListAll();
        return getDataTable(list);
    }

    /**
     * 导出股票库列表
     */
    @RequiresPermissions("web:gupiao:export")
    @Log(title = "股票库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GuGupiao guGupiao)
    {
        List<GuGupiao> list = guGupiaoService.selectGuGupiaoList(guGupiao);
        ExcelUtil<GuGupiao> util = new ExcelUtil<GuGupiao>(GuGupiao.class);
        util.exportExcel(response, list, "股票库数据");
    }

    /**
     * 获取股票库详细信息
     */
    @RequiresPermissions("web:gupiao:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(guGupiaoService.selectGuGupiaoById(id));
    }

    /**
     * 新增股票库
     */
    @RequiresPermissions("web:gupiao:add")
    @Log(title = "股票库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GuGupiao guGupiao)
    {
        return toAjax(guGupiaoService.insertGuGupiao(guGupiao));
    }

    /**
     * 修改股票库
     */
    @RequiresPermissions("web:gupiao:edit")
    @Log(title = "股票库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GuGupiao guGupiao)
    {
        return toAjax(guGupiaoService.updateGuGupiao(guGupiao));
    }

    /**
     * 删除股票库
     */
    @RequiresPermissions("web:gupiao:remove")
    @Log(title = "股票库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(guGupiaoService.deleteGuGupiaoByIds(ids));
    }


    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<GuGupiao> util = new ExcelUtil<GuGupiao>(GuGupiao.class);
        List<GuGupiao> gupiaoList = util.importExcel(file.getInputStream());
        String operName = SecurityUtils.getUsername();
        String message = guGupiaoService.importDate(gupiaoList, operName);
        return success(message);
    }

    @PutMapping("/upDateTag")
    public AjaxResult editTag(@RequestBody GuTagVo guTagVo)
    {
        return toAjax(guGupiaoService.updateGuGupiaoTag(guTagVo));
    }


}
